$trigger = New-JobTrigger -Daily -At "15:50"
$option=New-ScheduledJobOption -RunElevated
# $action={$dirpath="c:\hr\"+(Get-Date).ToString("yyyy-MM-dd")+".txt";New-Item -ItemType File $dirpath}

#$action={$filePath="c:\hr\"+(Get-Date).ToString("yyyy-MM-dd")+ ".txt";New-Item -ItemType File $filePath}

#$action={filePath = "c:\hr\" + (Get-Date).ToString("yyyy-MM-dd") + ".txt"; New-Item -ItemType File filePath -Force}


$action = {
    $dateString = (Get-Date).ToString("yyyy-MM-dd")
    $dirPath = "c:\hr\"
    
    # 确保目录存在
    if (!(Test-Path $dirPath)) {
        New-Item -ItemType Directory -Path $dirPath -Force
    }
    
    # 创建带.txt后缀的文件路径
    $filePath = Join-Path $dirPath "$dateString.txt"
    New-Item -ItemType File -Path $filePath -Force
}

Register-ScheduledJob -Name dailyFileCreated -Trigger $trigger -ScheduledJobOption $option -ScriptBlock $action

#Import-Module PSScheduledJob